package com.usian.controller;

import com.usian.feign.CotnentServiceFeign;
import com.usian.pojo.TbContentCategory;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 韩耀东
 * @date 2021/1/8 8:37
 */
@RestController
@RequestMapping("/content")
public class ContentCategoryController {
    @Autowired
    private CotnentServiceFeign cotnentServiceFeign;

    /**
     * @return com.usian.utils.Result
     * @Author 韩耀东
     * @Description //TODO
     * @Date 2021/1/8 9:07
     * @Param [parentId]
     **/
    @RequestMapping("/selectContentCategoryByParentId")
    public Result selectContentCategoryByParentId(@RequestParam(defaultValue = "0") Long id) {
        List<TbContentCategory> tbContentCategories = cotnentServiceFeign.selectContentCategoryByParentId(id);
        if (tbContentCategories.size() == 0) {
            return Result.error("您好，没有查询到该数据");
        }
        return Result.ok(tbContentCategories);
    }

    @RequestMapping("/insertContentCategory")
    public Result insertContentCategory(TbContentCategory tbContentCategory) {
        Integer contentCategoryNum = cotnentServiceFeign.insertContentCategory(tbContentCategory);
        if (contentCategoryNum == 1) {
            return Result.ok();
        }
        return Result.error("添加失败");
    }

    @RequestMapping("/updateContentCategory")
    public Result updateContentCategory(Long id,String name) {
        Integer contentCategoryNum = cotnentServiceFeign.updateContentCategory(id,name);
        if (contentCategoryNum == 1) {
            return Result.ok();
        }
        return Result.error("添加失败");
    }

    @RequestMapping("/deleteContentCategoryById")
    public Result deleteContentCategoryById(Long categoryId){
        Integer status = cotnentServiceFeign.deleteContentCategoryById(categoryId);
        if(status == 200){
            return Result.ok();
        }
        return Result.error("删除失败");
    }
}
